# Use an official Go runtime as a parent image
FROM golang:1.23.0 as builder

# Set the Current Working Directory inside the container
WORKDIR /app

# Copy the Go Modules manifests
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum are not changed
RUN go mod tidy

# Copy the source code into the container
COPY . .

# Build the Go app
RUN go build -o login .

# Start a new stage from a smaller image for the actual application
FROM alpine:latest  

# Install any required dependencies (like certificates, etc.)
RUN apk --no-cache add ca-certificates

# Set the Current Working Directory inside the container
WORKDIR /root/

# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/login .

# Expose port 8088 to the outside world
EXPOSE 8088

# Command to run the executable
CMD ["./login"]
